#!/bin/bash

# disable firewalld,selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# YUM
mkdir -p /etc/yum.repos.d/OldRepo
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/OldRepo/
curl -so /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -so /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs.com/d' /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/epel-7.repo

# sync time
yum install -y ntpdate
ntpdate ntp1.aliyun.com
hwclock -w
if [ ! -n "$(grep 'ntpdate' /var/spool/cron/root)" ];then
    echo "*/20 * * * * $(which ntpdate) ntp1.aliyun.com > /dev/null 2>&1 && $(which hwclock) -w" >> /var/spool/cron/root
    chmod 600 /var/spool/cron/root
fi

# quick start
sed -i 's/timeout=.*/timeout=1/g' /boot/grub2/grub.cfg

# quick down
cat <<EOF   >>/etc/systemd/system.conf

DefaultTimeoutStartSec=15s
DefaultTimeoutStopSec=15s
EOF
systemctl daemon-reload

# limits
if [ ! -n "$(grep 'add limits' /etc/security/limits.conf)" ];then
cat <<EOF  >>/etc/security/limits.conf

# add limits
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
* soft  memlock  unlimited
* hard memlock  unlimited
EOF
fi
